package com.ruoyi.web.controller.qiushi.mall;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.mall.TradePointOrder;
import com.ruoyi.qiushi.service.mall.ITradePointOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 积分商品订单Controller
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/qiushi/mall/tradepointorder")
public class TradePointOrderController extends BaseController {
    @Autowired
    private ITradePointOrderService tradePointOrderService;

    /**
     * 查询积分商品订单列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradepointorder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TradePointOrder tradePointOrder) {
        startPage();
        List<TradePointOrder> list = tradePointOrderService.selectTradePointOrderList(tradePointOrder);
        return getDataTable(list);
    }

    /**
     * 导出积分商品订单列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradepointorder:export')")
    @Log(title = "积分商品订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TradePointOrder tradePointOrder) {
        List<TradePointOrder> list = tradePointOrderService.selectTradePointOrderList(tradePointOrder);
        ExcelUtil<TradePointOrder> util = new ExcelUtil<TradePointOrder>(TradePointOrder.class);
        util.exportExcel(response, list, "积分商品订单数据");
    }

    /**
     * 获取积分商品订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradepointorder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tradePointOrderService.selectTradePointOrderById(id));
    }

    /**
     * 新增积分商品订单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradepointorder:add')")
    @Log(title = "积分商品订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TradePointOrder tradePointOrder) {
        tradePointOrder.setUpdateTime(new Date());
        return toAjax(tradePointOrderService.insertTradePointOrder(tradePointOrder));
    }

    /**
     * 修改积分商品订单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradepointorder:edit')")
    @Log(title = "积分商品订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TradePointOrder tradePointOrder) {
        return toAjax(tradePointOrderService.updateTradePointOrder(tradePointOrder));
    }

    /**
     * 删除积分商品订单
     */
    @PreAuthorize("@ss.hasPermi('qiushi:mall:tradepointorder:remove')")
    @Log(title = "积分商品订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        TradePointOrder tradePointOrder = new TradePointOrder();
        tradePointOrder.setUpdateTime(new Date());
        tradePointOrder.setDelFlag("1");
        tradePointOrder.setId(id);
        return toAjax(tradePointOrderService.updateTradePointOrder(tradePointOrder));
    }
}
